package StrBuffer;

public class StringAppend {

	static long times=50000; //100W 
	public static void main(String[] args) {

		stringPlus();
		stringConcat();
		stringBufferAppend();
		stringBuilderAppend();
	}
	
	
	static void stringPlus(){
		
		long start = System.currentTimeMillis();
		
		String test = "";
		for(long i = 0; i < times; i++){
			
			test+=i;
		}
		
		System.out.println("string plus :"+(System.currentTimeMillis() - start)+"ms");
		
	}
	
	
	static void stringConcat(){
		
		long start = System.currentTimeMillis();
		
		String test = "";
		for(long i = 0; i < times; i++){
			
			test.concat(String.valueOf(i));
		}
		
		System.out.println("string concat :"+(System.currentTimeMillis() - start)+"ms");
		
	}
	
	
	static void stringBufferAppend(){
		
		long start = System.currentTimeMillis();
		
		StringBuffer strBuffer = new StringBuffer();
		for(long i = 0; i < times; i++){
			
			strBuffer.append(i);
		}
		
		System.out.println("string buffer :"+(System.currentTimeMillis() - start)+"ms");
		
	}
	
    static void stringBuilderAppend(){
		
		long start = System.currentTimeMillis();
		
		StringBuilder strBuilder = new StringBuilder();
		for(long i = 0; i < times; i++){
			
			strBuilder.append(i);
		}
		
		System.out.println("string builder :"+(System.currentTimeMillis() - start)+"ms");
		
	}

}
